import { cache } from '@/utils/functions'
import { encrypt, decrypt } from "@/utils/crypto";
import Store from './index'
const checkMap = {
    // {storage缓存名: store mutations名}，尾部带*sessionStorage表示从获取，尾部带&表示uniapp存的数据 否则都是获取localStorage
    "account": "user/SET_USER_ACCOUNT",
    "tabsList*": "tabs/SET_TABS_LIST",
    "activeRoute*": "tabs/SET_ACTIVE_ROUTE",
    "powerList": "control/SET_POWER_LIST",
}

const check = () => {
    Object.keys(checkMap).forEach(key => {
        if(key == 'account') {
            if(localStorage.account) {
                let accountStr = cache.read(key)
                let AccData = decrypt(
                    accountStr.slice(16, -16),
                    accountStr.slice(-16).toLowerCase(),
                    accountStr.slice(0, 16).toLowerCase()
                );
                console.log(AccData);
                Store.commit(checkMap[key], AccData);
            }
        } else {
            let storage;
            storage = cache.read(key.replace(/[\*]/, ""), key.slice(-1) == '*')
            if (storage) {
                Store.commit(checkMap[key].replace(/[*]/, ""), storage);
            }
        }
    })
}
export default check
